<?php



namespace app\home\controller;

use think\Controller;

class Base extends Controller
{
    //公共调用
    public function response($code = 200, $msg = '', $data = [])
    {
        //返回结果
        $res = [
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        ];
        json($res)->send();
        die;
    }
    //成功时的响应
    public function ok($data = [], $code = 200, $msg = 'success')
    {
        $this->response($code, $msg, $data);
    }
    //失败时的响应
    public function fail($msg = 'fail', $code = 500)
    {
        return $this->response($code, $msg);
    }
}
